import java.sql.SQLOutput;

class Test4 {
    public String truncateSentence(String s, int k) {
        String ret = "";
        int n = 0;
        int i = 0;
        while(n<k){
            if(s.charAt(i) != ' '){
                ret = ret + s.charAt(i);
            }else{
                ret = ret + " ";
                n++;
            }
            i++;
        }
        return ret;
    }

    public static void main(String[] args) {
        Test4 test4 = new Test4();
        String s = "asd asdas asd asd";
        System.out.println(test4.truncateSentence(s,4));

    }
}
